﻿using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Billing2
{
    public partial class ViewChanges : System.Web.UI.Page
    {
        //private void GetPermission()
        //{
        //    ClsACLHelper cls = new ClsACLHelper();
        //    string pageName = this.Page.ToString().Substring(4, this.Page.ToString().Substring(4).Length - 5) + ".aspx";
        //    cls.SetPermission(LoginUser.TreeMenu, pageName);
        //    this.Create0 = cls.Create0;
        //    this.Delete0 = cls.Delete0;
        //    this.Read0 = cls.Read0;
        //    this.Update0 = cls.Update0;
        //    if (!cls.Read0)
        //    {
        //        base.Response.Redirect("logout.aspx", true);
        //    }
        //}

        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.Session["SiteID"] == null)
            {
                base.Response.Redirect("default.aspx", true);
            }
            try
            {
                if (!this.Page.IsPostBack)
                {
                    long report_id = 0;
                    if (this.PreviousPage is ReleaseBillReport)
                        report_id = Convert.ToInt64(Common.DecryptData(((ReleaseBillReport)this.PreviousPage).ReportID));
                    else if (this.PreviousPage is DownloadBillReport)
                        report_id = Convert.ToInt64(Common.DecryptData(((DownloadBillReport)this.PreviousPage).ReportID));
                    else
                        throw new Exception("Invalid page! except ReleaseBillReport or DownloadBillReport.");

                    DataTable dt = new DataTable();
                    int rdlc_id = 0;
                    DBCommands2.TBL_BillReportRepository report = Common.db.BillReportRepository.selectPK2(report_id);
                    switch (report.BillReportTemplateID)
                    {
                        case 1:
                        case 9: dt = DBCommands2.BillReportData_Diff(report_id); rdlc_id = 1; break;
                    }
                    if (dt == null)
                    {
                        this.ucHighlight1.Message = "No report data to compare!";
                        return;
                    }

                    this.ReportViewer1.Reset();
                    this.ReportViewer1.LocalReport.ReportEmbeddedResource = "Billing2.Report" + rdlc_id.ToString() + ".rdlc";
                    this.ReportViewer1.LocalReport.DataSources.Clear();
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
                    this.ReportViewer1.LocalReport.Refresh();
                }
                //this.GetPermission();
            }
            catch (Exception ex)
            {
                EPPLog.Logger.Error(MyLib.Utility.ExceptionInfo(ex));
            }
        }

        protected void Page_LoadComplete(object sender, EventArgs e)
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            ViewStateUserKey = Session.SessionID;
        }

        public bool Create0
        {
            get
            {
                return Convert.ToBoolean(this.ViewState["xCreate0"]);
            }
            set
            {
                this.ViewState["xCreate0"] = value;
            }
        }

        public bool Delete0
        {
            get
            {
                return Convert.ToBoolean(this.ViewState["xDelete0"]);
            }
            set
            {
                this.ViewState["xDelete0"] = value;
            }
        }

        public bool Read0
        {
            get
            {
                return Convert.ToBoolean(this.ViewState["xRead0"]);
            }
            set
            {
                this.ViewState["xRead0"] = value;
            }
        }

        public bool Update0
        {
            get
            {
                return Convert.ToBoolean(this.ViewState["xUpdate0"]);
            }
            set
            {
                this.ViewState["xUpdate0"] = value;
            }
        }
    }
}